package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsColumnConfig;
import com.econ.powercloud.ems.dal.mapper.EmsColumnConfigMapper;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 报表对应的列 DAO
 * @Date : 2021/9/24 14:29
 * @Modified by : zjf
 */
@Repository
public class EmsColumnConfigDAO extends ServiceImpl<EmsColumnConfigMapper, EmsColumnConfig> {

    /**
     * 通过储能站id,储能装置id,电表设备类型 获取需要展示的列数据
     * @param stationId
     * @param equipmentId
     * @param deviceType: 参见DeviceType枚举
     * @param reportId: 报表类型
     * @return
     */
    public List<EmsColumnConfig> getListByCondition(String stationId, String equipmentId, Integer deviceType, String reportId){
        LambdaQueryWrapper<EmsColumnConfig> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(EmsColumnConfig::getEnergyStationId,stationId);
        lambdaQueryWrapper.eq(!StringUtils.isNullOrEmpty(equipmentId), EmsColumnConfig::getEnergyEquipmentId,equipmentId);
        lambdaQueryWrapper.eq(deviceType!=null,EmsColumnConfig::getDeviceType,deviceType);
        lambdaQueryWrapper.eq(EmsColumnConfig::getReportId,reportId);
        return this.baseMapper.selectList(lambdaQueryWrapper);
    }

    public List<EmsColumnConfig> selectAll(){
        return this.baseMapper.selectAll();
    }

    public int deleteByStation(String stationId){
        LambdaQueryWrapper<EmsColumnConfig> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(EmsColumnConfig::getEnergyStationId,stationId);
        return this.baseMapper.delete(lambdaQueryWrapper);
    }
}
